// 模拟一维 结构体数组
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// 结构体声明
struct student
{
    int id;
    char name[32];
    int age;
};

int main(int argc, char **argv)
{
    struct student **p = NULL;
    int i = 0;

    // 设置随机数种子
    srand(time(NULL));

    // 申请空间
    p = malloc(sizeof(struct student *));
    if (NULL == p)
    {
        return 1;
    }

    *p = calloc(5, sizeof(struct student));
    if (NULL == *p)
    {
        return 1;
    }

    // 随机数赋值
    for (i = 0; i < 5; i++)
    {
        sprintf((*p + i)->name, "%c%c%c%c%c", 
            (char)('A' + rand() % 26),
            (char)('a' + rand() % 26),
            (char)('a' + rand() % 26),
            (char)('a' + rand() % 26),
            (char)('a' + rand() % 26)
            );
    }

    // 输出
    for (i = 0; i < 5; i++)
    {
        printf("%s\n", (*p + i)->name);
    }

    // 释放空间
    free(*p);
    free(p);
    p = NULL;
    return 0;
}